<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>${aier_title}</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    	
	<meta http-equiv="Content-Type" content="${aier_content_type}" >
	<meta name="keywords" content="${aier_keyworks}" >
	<meta name="description" content="${aier_description}" >
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel='stylesheet' type='text/css' href="${aier_new_css_url}assets/stylesheets/bootstrap/bootstrap.css" >
	<link rel='stylesheet' type='text/css' href="${aier_new_css_url}assets/stylesheets/bootstrap/bootstrap-responsive.css">
	<link rel='stylesheet' type='text/css' href="${aier_new_css_url}assets/stylesheets/jquery_ui/jquery-ui-1.10.0.custom.css" >
	<link rel='stylesheet' type='text/css' href='${aier_new_css_url}assets/stylesheets/plugins/bootstrap_switch/bootstrap-switch.css' media='all'  >
    <link rel='stylesheet' type='text/css' href='${aier_new_css_url}assets/stylesheets/light-theme.css' >
    <link rel='stylesheet' type='text/css' href='${aier_new_css_url}assets/stylesheets/demo.css'    >
    <link rel='stylesheet' type='text/css' type='text/css' href="${aier_new_css_url}admin/comwap.css"   >	
    <link rel="stylesheet" type='text/css' href="${aier_new_css_url}assets/stylesheets/plugins/jcrop/jquery.Jcrop.min.css" />
	<link rel="stylesheet" type='text/css' href="${aier_new_css_url}assets/stylesheets/plugins/jcrop/jquery.Jcrop.css" />
	<link rel="stylesheet" type='text/css' href="${aier_css_url}assets/stylesheets/plugins/jquery_fileupload/jquery.fileupload-ui.css" />    
    <style type="text/css">
			.change{		 	
				margin-top:15px;
				margin-right:30px;
				float:right;}
			.change2{
			margin-right:10px;
				float:right;}
			.test{	
				float:left;
				 margin: 15px auto 15px 35px;
			}
			 ul,li {
						margin: 0;
						padding: 0;
						list-style: none;
			}
			.imglist{
				float:left;
				width:500px;
				margin: 15px auto 15px 10px;
			}
			.info{
				float:left;
				  margin: 15px auto 15px 35px;
				}
			.about{
					float:left;
				width:500px;
				 margin: 15px auto 15px 35px;
					}
			.teacherlist{
						float:left;
						width:500px;
						margin: 15px auto 15px 30px;
						}
			.teacherfirst{
				margin:auto auto 10px auto;
				}
				.teacher{
					margin:10px auto 10px auto;
					}
				
			.imglist li img{	
						float:left;
						width:100px;
						height:120px;
						margin-left:2px;
						margin-bottom:2px;
			}
			.tx{
				float:left;
						width:58px;
						height:58px;
						margin-left:2px;
						margin-bottom:2px;
				}		
			.tablemain {
				color:#333333;
				border-collapse: collapse;
				border-width: 2px;
				border-style: solid;
				border : 2px #D3D3D3  solid 
								}
							
			.tablemain td{
				border-width: 2px;
				border-style: solid;
				border-color:#D3D3D3;
				cellSpacing:0; cellPadding:0;
				border-bottom: 2px #D3D3D3 solid;
				border-top:none;
				border-left:none;
				border-right:none;
			}					
		</style>
	</head>
  
  <body >

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>
	<!-- 顶栏结束 -->

	    <br>
		<div class="container-fluid" style="margin-top: 90px;">
		<!-- wrap  -->
			<div class="row-fluid" >
				<div class ='span1'style="margin-left: 150px;">
					<!--菜单栏  -->
					<s:action name="menus_schoolMenus" namespace="/nxadmin" executeResult="true" ></s:action>
					<!--菜单栏结束  -->
				</div>
				
				<!-- 主区域 (右  -->
				<div class="span9" style="margin-left:70px;" >				
							<div class="right-main-top" style="font-size: 16px;">
								<div><a>&nbsp;&nbsp;&nbsp;</a><strong style="margin-top: 10px;margin-top: 20px;">学校信息</strong></div>
							</div>

							<table width="950px;" class="tablemain">
								  <tbody>
								        <tr>
								       	  <td>
								           	<div class="test">
								  				 学校头像：
								             </div> 
								              <div class="imglist" >
								               	  <ul>
								                   	  <li>
								                		<img id="schoollogo" src=""   style='width:25%;height:25%;' />
								                      </li>
								               	  </ul>
								              </div> 
								              <span class="change" id="btnscname"><a id="inside" href="javascript:void(0);"  onclick="updateschoolinfo();" >修改</a></span>
								            </td>
								        </tr>
								        
								        <tr>
								       	  	<td id="scname">
								            	<div class="test">
								  				 学校名称：
												</div>
												<div id="am"  >
													<div id="aa" >
									                	<div class="info" id="schoolname"></div>
									               		 <span class="change">
									                	 <a id="sa" href="javascript:void(0);"  onclick="updatescname()" >修改</a>
									                 	</span>
								                	 </div>
								                 </div>
									        </td>
								        </tr>
						                <tr>
								       	  <td>
								           	<div class="test">
								  				  简介：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								             </div> 
								             <div id="mab">
									             <div class="about" id="desinfo">
									             </div> 
									              <span  class="change"><a href="javascript:void(0);" onclick="updatescdesinfo();">修改</a></span>
								              </div>
								              <div id="mac">
								              </div>								          
								           </td>
								        </tr>
								        <tr>
								       	  <td>
								           	<div class="test">
								  				 联系方式：
								             </div> 
									              <div class="teacherlist"  >
									                                <div class="teacherfirst">
									                                   [地址]： <span id="address">
									                                         </span>
									                                </div> 
									                                
									            	    			<div class="teacher">
									                                    [电话]： <span id="phone">
									                                          </span>
									                                </div> 
									
									                                <div class="teacher">
									                                     [邮编]： <span id="postcode">
									                                          </span>
									                                </div> 
									
									                                <div class="teacher">
									                                    [传真]： <span id="fax">
									                                      	  </span>
									                                </div>
									                                										
									                                <div class="teacher">
									                                    [电子邮件]： <span id="email">
									                                      	  </span>
									                                </div> 
									                                										
									                                <div class="teacher">
									                                    [网站地址]： <span id="url">
									                                      	    </span>
									                                </div>
									                  </div> 
									                 
									                  	<span class="change" id="testspana">
									                  		<a  href="javascript:void(0);"  onclick="updatescoolinfo();">修改</a>
									                  	</span>	
									                  	<span  class="change" id="testspanb" >
									                  	<a id='sasv' href='javascript:void(0);'  class='btn btn-small btn-success' onclick='savetest();' >保存</a> 
									                  	<a id='sacl' href='javascript:void(0);'   class='btn btn-small' onclick='chanletest()'>取消</a>
									                  	</span>
									                  	
								            </td>
								        </tr>
										<tr>
								       	  <td>
								           	<div class="test">
								  				 园长信息：
								             </div> 
								             <div id="stlistinfo">
								              				<div class="teacherlist"  >
									                                <div class="teacherfirst" >
									                                   [姓名]： <span id="teachername" >
									                                         </span>
									                                </div> 
									                                
									            	    			<div class="teacher">
									                                    [电话/手机/座机]： <span id="teachercal">
									                                          </span>
									                                </div> 
									
									                                <div class="teacher">
									                                     [邮件]： <span id="teacheremail">
									                                          </span>
									                                </div> 
									
									                                <div class="teacher">
									                                     [QQ]： <span id="teacherqq">
									                                      	  </span>
									                                </div>
								             					 </div> 
								             </div>
								              		<span id="testspanc" class="change"><a href="javascript:void(0);" onclick="updatescoolteacherinfo();" >修改</a></span>
								              		
								              		<span id="testspand" class="change" >
									                  	<a id='sasv' href='javascript:void(0);'  class='btn btn-small btn-success' onclick='saveTeacher();' >保存</a> 
									                  	<a id='sacl' href='javascript:void(0);'   class='btn btn-small' onclick='chanletesta();'>取消</a>
									                </span>
								            </td>
										 </tr>                  
								  </tbody>  
							</table>	
		</div>	
	</div>
</div>

	<div id='loadimg'  title="上传LOGO" style="background-color: rgb(243,243,243);">
		<div class="row">
			<div  class="span5">
					<div class="" style="margin: 40px auto auto  20px ; ">
								<span>你可以对图片进行剪切和预览</span><br>
								<div style="float: left;">
										<div id="imgsrc" class="tab01-cen-l">
											<img id='imgpath' style='width:100%;height:100%;' src="">
											<input type="hidden" id="x" name="x" /> <input type="hidden"
												id="y" name="y" /> <input type="hidden" id="w" name="w" />
											<input type="hidden" id="h" name="h" />
											<button id="cut" onclick="getCutImg();" style="display: none;" class="btn btn-success btn-mini">确认</button>
										</div>
								</div>
								<div style="float: left;">
										<div class="cen-r-ap">
											<span id="preview_box" class="crop_preview">
											<img id="crop_preview" style="width: 100%;height: 100%;" src="" /><br/>
											</span>
										</div>
										<div class ="cen-r-file">
											<div style="margin-left: 10px;" >
													 <label style="cursor: default;" for="file"> 
													 <a id="b_selfile" ><i class="icon-file"></i>  选择文件</a>
													  </label>
													 <input class="input_opacity" type="file" id="file" name="file" onchange="txt_path.value=this.value">
													 <input id="txt_path" type="text" class="PY-input" readonly="readonly">
													 <a onclick="upfile();" class="btn" href="javascript:;">上传 </a>
											</div>
											  <span>仅支持JPG、JPEG、GIF、PNG格式文件小于2M</span>
										</div>
								</div>
					</div>
			</div>
			<div class="span3">
			     	<img alt="" src="${aier_new_img_url}3up.png">
			</div>
		</div>
	</div> 
<script src="${aier_new_js_url}assets/jquery/jquery-1.9.0.min.js" type="text/javascript" ></script>
<script src="${aier_new_js_url}assets/bootstrap/bootstrap.min.js" type="text/javascript" ></script>
<script src="${aier_new_js_url}assets/jquery_ui/jquery-ui.min.js" type="text/javascript" > </script> 
<script src="${aier_new_js_url}assets/jquery_ui/jquery-ui-1.10.0.custom.min.js" type="text/javascript"></script>
<script src="${aier_new_js_url}assets/plugins/fileupload/ajaxfileupload.js"   type="text/javascript"></script>
<script type="text/javascript" src="${aier_js_url}jcrop/jquery.Jcrop.min.js "></script>
<script type="text/javascript" src="${aier_js_url}jcrop/jquery.Jcrop.js" ></script>
	<script type="text/javascript">
		$(function() {
			$('#testspanb').hide();
			$("#testspand").hide();
		});
	</script>
<script type="text/javascript">
	
	function cutPicture() {
		$("#imgpath").Jcrop({
			onChange : showCoords,
			onSelect : showCoords,
			aspectRatio : 1
		});
		function showCoords(obj) {
			$("#x").val(obj.x);
			$("#y").val(obj.y);
			$("#w").val(obj.w);
			$("#h").val(obj.h);
			if (parseInt(obj.w) > 0) {
				//计算预览区域图片缩放的比例，通过计算显示区域的宽度(与高度)与剪裁的宽度(与高度)之比得到
				var rx = $("#preview_box").width() / obj.w;
				var ry = $("#preview_box").height() / obj.h;

				//通过比例值控制图片的样式与显示
				$("#crop_preview").css({
					width : Math.round(rx * $("#imgpath").width()) + "px", //预览图片宽度为计算比例值与原图片宽度的乘积
					height : Math.round(rx * $("#imgpath").height()) + "px", //预览图片高度为计算比例值与原图片高度的乘积
					marginLeft : "-" + Math.round(rx * obj.x) + "px",
					marginTop : "-" + Math.round(ry * obj.y) + "px"
				});
			}
		}
	}
</script>

<script type="text/javascript">
	$( "#loadimg" ).dialog({
	    autoOpen: false,
		width: 850, 
		height: 500,	
	     show: {
	        effect: "blind",
	        duration: 1000
	      },
	      hide: {
	        effect: "explode",
	        duration: 1000
	      },
		   modal: true,
	    buttons: {
	        '确定': function () {
	            $(this).dialog('close');
	            window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
	        	},
			'取消': function () {
	            $(this).dialog('close');
	            window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
	        	}
	    	}
		});	 
</script>

<script type="text/javascript">
		var sid =${sid};// 学校ID
		//学校主体信息
		function loadSchoolinfo(){	
			$.ajax({ 
		           type: "post", 
	               url:  "${aier_url}${aier_urijs}school_serachAvatar.shtml", 
	               data:{"sid":sid},
	               dataType: "json", 
	               timeout:15000,
	               success: function (data) { 
	            	   if(data.s==1){
	            		   $('#schoollogo').attr("src", "${schoollogo_get_url}small/" + data.school.slogo + "");
	            		   $('#schoolname').append(data.school.name);//data.school.name
	            		   $('#desinfo').append(data.school.desinfo);//
	            		   
	            		   $('#address').append(data.schoolInfoDetail.address);//
	            		   $('#phone').append(data.schoolInfoDetail.phone);//
	            		   $('#postcode').append(data.schoolInfoDetail.postcode);//
	            		   $('#fax').append(data.schoolInfoDetail.fax);//
	            		   $('#email').append(data.schoolInfoDetail.email);//
	            		   $('#url').append(data.schoolInfoDetail.url);//
	            		   
	            		   $('#teachername').append(data.user.realname);//
	            		   $('#teachercal').append(data.user.phone);//
	            		   var sd=data.user.email;
	            		   var  arr=sd.split(",");
	            		   $('#teacheremail').append(arr[0]);//
	            		   $('#teacherqq').append(arr[1]);//
	            	   }
	               }, 
	               error: function (XMLHttpRequest, textStatus, errorThrown) { 
	                       alert(errorThrown); 
	               } 
	       });
		}

		function updateschoolinfo (){
			$('#inside').bind('click',function(){
					//提示发送框
				$( "#loadimg" ).dialog("open");
			});
		}
		
		loadSchoolinfo();
</script>
	
<script type="text/javascript">
	var imgName = "";
	// 上传文件
	function upfile() {
		var pName = $("#file").val().split("\\")[2];
		if (pName==null){
			alert("请选择图片！");
			return;
		}
		var pname1 = pName.substring(pName.lastIndexOf('.')).toLowerCase();
		try {
			$.ajaxFileUpload({
						url : "${aier_url}schooljs/sbinfo_updateSchoolLogo${aier_suffix}",
						fileElementId:'file',
						dataType: 'json',
						data:{sid:${sid}, photoName:pname1},
						success : function(data, status) {
							alert("上传成功");
							$('#cut').show();
							$('#imgpath').attr("src","${schoollogo_get_url}small/" + data.slogo + "");
							$('#crop_preview').attr("src","${schoollogo_get_url}small/" + data.slogo + "");
							imgName = data.slogo;
							cutPicture();
						},
						error : function(data, status, e) {
							alert("服务器连接超时");
						}
					});
		} catch (e) {
			alert("服务器连接超时");
		}
	}

	function getCutImg() {
		if (parseInt($("#x").val()) > 0 && parseInt($("#y").val()) > 0) {
			$.ajax({ 
			 	type: "post", 
            	url:  "${aier_url}schooljs/sbinfo_cutImg${aier_suffix}", 
           	 	data:{"sid":${sid},"slogo":imgName,"x" : $('#x').val(),"y" : $('#y').val(),"w" : $('#w').val(),"h" : $('#h').val(),},
            	dataType: "json", 
            	success: function (data) { 
            		if (data.s == 1) {
    					alert("保存成功");
    					$('#cut').hide();
    					 location.reload();
    					//AvaTemDivP();
    				} else {
    					alert("保存失败");
    				}
	            }, 
	            error: function (XMLHttpRequest, textStatus, errorThrown) { 
	                    alert(errorThrown); 
	            } 
			});
		} else {
			alert("请先在图片上划一个选区再单击确认！");
			return;
		}
	}

	function AvaTemDivP() {
		$.ajax({
	           	type: "post", 
            	url:  "${aier_url}schooljs/sbinfo_serachAvatar${aier_suffix}", 
           	 	data:{"sid":sid},
            	dataType: "json", 
            	success: function (data) { 
            		if (data.slogo != null) {
        				$('#crop_preview').attr("src", "${schoollogo_get_url}small/" + data.slogo + "");
        			} else {
        				$('#crop_preview').attr("src", "${schoollogo_get_url}small/${school.slogo}");
        			}
	            }, 
	            error: function (XMLHttpRequest, textStatus, errorThrown) { 
	                    alert(errorThrown); 
	            } 
    	});
	}
	AvaTemDivP();

	//修改学校 名称
	function updatescname(){
		$("#aa").hide();	
		save=function(){
			$.ajax({ 
				type: "post", 
	        	url:  "${aier_url}schooljs/sbinfo_updateSchoolInfo${aier_suffix}", 
	       	 	data:{ "sid":${sid},"name": $("#inputscname").val(),"img":"${school.slogo}","desinfo":"${school.desinfo}" },
	        	dataType: "json", 
	        	success: function (data) { 
	        		if (data.s == 1) {
	        			 window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
					} else {
						alert("保存失败");
					}
	            }
	       	 	
			});
		};
		
		chanle=function(){
			var s=$("#aa2");
			s.remove();
			$("#aa").show();
		};
		var div="<div id='aa2' style='margin:10px 0 0 5px;' ><input type='text' id='inputscname' ><span class='change2'><a id='sasv' href='javascript:void(0);'  class='btn btn-small btn-success' onclick='save();' >保存</a> <a id='sacl' href='javascript:void(0);'   class='btn btn-small' onclick='chanle()'>取消</a></span></div>";
		$("#am").append(div);
	}
	
	//修改学校desinfo
	function updatescdesinfo(){
		$("#mab").hide();
		save=function(){
			$.ajax({
				type: "post", 
	        	url:  "${aier_url}schooljs/sbinfo_updateSchoolInfo${aier_suffix}", 
	        	data:{ "sid":${sid},"name": "${school.name}","img":"${school.slogo}","desinfo":$('#textarea').val() },
	        	dataType: "json", 
	        	success: function (data) { 
	        		if (data.s == 1) {
	        			 window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
					} else {
						alert("保存失败");
					}
	            }
			});
		};
		
		chanle=function(){
			var s=$("#mac");
			s.empty();
			$("#mab").show();
		};
		
		var div="<div class='about' >"+
				"<textarea rows='10' id='textarea'   style='height:150px; width:500px; border：1px  #C2CAFC soild; margin-top:15px; ' placeholder='填写学校信息'></textarea>"+
				" </div>"+
				"<span class='change' >"+
				" <a id='sasv' href='javascript:void(0);'  class='btn btn-small btn-success' onclick='save();' >保存</a>"+
				" <a id='sacl' href='javascript:void(0);'   class='btn btn-small' onclick='chanle()'>取消</a>"+" </span>";
		$("#mac").append(div);
	
}

function updatescoolinfo (){
	$("#testspana").hide();
	$("#testspanb").show();
	$("#address").html(" <input type='text' id='inputaddress' > ");
	$("#phone").html(" <input type='text' id='inputphone' > ");
	$("#postcode").html(" <input type='text' id='inputpostcode' > ");
	$("#fax").html(" <input type='text' id='inputfax' > ");
	$("#email").html(" <input type='text' id='inputemail' > ");
	$("#url").html(" <input type='text' id='inputurl' > ");
}

function removeMain(){
	 $('#schoollogo').attr("src", "");
	 $('#schoolname').empty();//data.school.name
	 $('#desinfo').empty();//
	   
	 $('#address').empty();//
	 $('#phone').empty();//
	 $('#postcode').empty();//
	 $('#fax').empty();//
	 $('#email').empty();//
	 $('#url').empty();//
	 $('#teachername').empty();//
	 $('#teachercal').empty();//
	 $('#teacheremail').empty();//
	 $('#teacherqq').empty();//
}

function remove(){
	removeMain();
	$("#inputaddress").remove();
}

function chanletest(){
	remove();
	loadSchoolinfo();
	$('#testspana').show();
	$('#testspanb').hide();
}

function savetest(){
	var inputaddress =$("#inputaddress").val();
	var inputphone =$("#inputphone").val();
	var inputpostcode =$("#inputpostcode").val();
	var inputfax =$("#inputfax").val();
	var inputemail =$("#inputemail").val();
	var inputurl =$("#inputurl").val();
	
	var regBox = {
		        regEmail : /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/,//邮箱
		        regMobile : /^0?1[3|4|5|8][0-9]\d{8}$/,//手机
		        regTel : /^0[\d]{2,3}-[\d]{7,8}$/
		    }
	 
	if(inputaddress=="" || inputphone=="" || inputpostcode==""  || inputfax ==""  || inputemail==""  ||  inputurl==""  ){
		alert("请把信息填写完整!");
		return false ;
	}
	 //phone, address, url, postcode,email,fax
	 $.ajax({
		 	type: "post", 
     		url:  "${aier_url}schooljs/sbinfo_updateSchoolInfoDetail${aier_suffix}", 
     		data:{ "sid":${sid},"phone":inputphone,"address":inputaddress,"url":inputurl,"postcode":inputpostcode,"email":inputemail,"fax":inputfax },
     		dataType: "json", 
     		success: function (data) { 
        		if (data.s == 1) {
        			 //window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
        			 chanletest();
				} else {
					alert("保存失败");
				}
            }
	 });
}

function  updatescoolteacherinfo(){
	$("#testspanc").hide();
	$("#testspand").show();
	$("#teachername").html(" <input type='text' id='inputteachername' > ");
	$("#teachercal").html(" <input type='text' id='inputteachercal' > ");
	$("#teacheremail").html(" <input type='text' id='inputteacheremail' > ");
	$("#teacherqq").html(" <input type='text' id='inputteacherqq' > ");
	
}

function chanletesta(){
	removeMain();
	loadSchoolinfo();
	$('#testspanc').show();
	$('#testspand').hide();
}


//更新园长信息
function saveTeacher(){
	var inputname =$("#inputteachername").val();
	var inputcal =$("#inputteachercal").val();
	var inputemail =$("#inputteacheremail").val();
	var inputqq =$("#inputteacherqq").val();
	
	if(inputname=="" || inputname=="" || inputemail==""  || inputqq =="" || inputcal=="" ){
		alert("请把信息填写完整!");
		return false ;
	}

	$.ajax({
			type: "post",
			url: "${aier_url}userjs/useraccountsettings_upUserinfo${aier_suffix}",
			data:{"uid": ${user.uid} , "email":$("#inputteacheremail").val()+","+$("#inputteacherqq").val() , "phone":$("#inputteachercal").val() , "realname":$("#inputteachername").val()},
			dataType: "json",
			success: function (data) { 
        		if (data.s == 1) {
        			 //window.location.href = "${aier_url}${aier_uri}school_schoolManager${aier_suffix}?uid="+${uid}+"&sid="+${sid};
        			 alert("保存成功");
        			 chanletesta();
				} else {
					alert("保存失败");
				}
            }
	});
}
</script>
</body>
</html>